package com.gjp.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.gjp.myapplication.adapter.PhotoAdapter;
import com.gjp.myapplication.bean.ImageItem;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class PhotoList2Activity extends AppCompatActivity {

    private List<String> listData;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.photo_list);
        setTitle("相册");
        init();
    }

    private void init() {
        // 获取传值
        final ImageItem[] imageItems = (ImageItem[]) getIntent().getSerializableExtra("data");
        // 解析出所有图片链接
        listData = new ArrayList<>();
        for (ImageItem imageItem : imageItems) {
            listData.add(imageItem.getUrl());
        }

        PhotoAdapter adapter = new PhotoAdapter(Arrays.asList(imageItems));
        RecyclerView recyclerView = findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new GridLayoutManager(PhotoList2Activity.this, 2));
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(new PhotoAdapter.OnItemClickListener() {
            @Override
            public void onClick(View v, int position) {
                // 点击跳转到图片列表页面
                Intent intent = new Intent(PhotoList2Activity.this, PhotoList3Activity.class);
                intent.putExtra("data", imageItems);
                startActivity(intent);
            }
        });

    }
}